#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int biao[11] = {0,1,4,4,2,1,1,4,4,2};

int a,b,c;

ll pp(ll x,ll t){ll res=1;for(;t;t>>=1,x=x*x%10)if(t&1)res=res*x%10;return res;}

ll ppow(ll x,ll t){ll res=1;for(;t;t>>=1,x=x*x%biao[a])if(t&1)res=res*x%biao[a];return res;}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	a = in,b = in,c = in;
	a %= 10; if(a == 0) return puts("0"),0;
	int t = ppow(b % biao[a],c); int ans = 0;
	if(!t) ans = pp(a,biao[a]);
	else ans = pp(a,t);
	printf("%d\n",ans % 10);
	return 0;
}

